﻿using System;
using QzEbook.Admin;
using System.Text;
using System.Web;
using QzEbook.AccessObject;
using QzEbook.Common;

namespace QzEbook.BaseView
{
    public class CheckPage:BasePage
    {
        protected SessionUser userSession=null;
        public CheckPage()
        {
        }

        /// <summary>
        /// 是否登陆;
        /// </summary>
        public void checkUser()
        {
            userSession = SessionManager.LoginUser;
            if (userSession == null)
            {
                Response.Redirect("~/admin/Login.xhtml");
                return;
            }
        }
        /// <summary>
        /// 是否登陆;
        /// </summary>
        /// <param name="url">登陆后的导向地址</param>
        public void checkUser(string url)
        {
            userSession = SessionManager.LoginUser;
            if (userSession == null)
            {
                Response.Redirect(string.Format("~/admin/Login.xhtml?raw={0}",Server.UrlEncode(url)));
                return;
            }
        }

        /// <summary>
        /// 取得用户信息;
        /// </summary>
        /// <returns></returns>
        public SiteUser getUserInfo()
        {
            //只有调用后才会有userSession对像;
            if (userSession == null)
            {
                checkUser();
            }
            SiteUser siteUser = new SiteUser();
            siteUser.Uid = userSession.Uid;
            siteUser=siteUser.select();
            return siteUser;
        }
    }
}